﻿using System;
using Ensemble_Windows;
using Ensemble_Windows.UI;
using NLua;
using SharpDX.Direct2D1;

namespace EnsembleGame
{
    /// <summary>
    /// 主逻辑入口点
    /// </summary>
    public class MainGame : Game
    {
        private Lua Lua_state { get; set; }
        /// <summary>
        /// 初始化游戏
        /// </summary>
        /// <param name="configuration">配置</param>
        protected override void Initialize(Configuration configuration)
        {
            base.Initialize(configuration);
            //configuration.Title=
            // 新增lua接口 config 游戏配置
           // base.Lua_state["config"] = configuration;
            //LuaHelper.LoadScript<Configuration>(Mod.LuaInitPath, base.Lua_state, configuration);
            
            //创建一个窗口(宽,高,位置(x.y),载体)
            Panel loginPanel = PanelHelper.Create(0, 0, new System.Drawing.Point(100, 100), _form); 
            //放大到载体大小           
            loginPanel.Dock = System.Windows.Forms.DockStyle.Fill;
             //设置窗口背景图  
            loginPanel.BackgroundImage = System.Drawing.Image.FromFile(@"Resource\ui1.jpg");

            //创建一个按钮
            Button startButton = ButtonHelper.Create();
            //按钮加入窗口
            loginPanel.Controls.Add(startButton);
            //按钮位置设置
            int x = startButton.Width / 2;
            startButton.Location = new System.Drawing.Point(400+x, 500);
            //改变按钮名称
            startButton.Text = "开始游戏";




            ProgressBar progress = new ProgressBar();
            progress.Width = 500;
            _form.Controls.Add(progress);

            Panel panel = new Panel()
            {
                Dock = System.Windows.Forms.DockStyle.Fill,
            };
            _form.Controls.Add(panel);


            for (int i = 0; i < Num_x; i++)
            {
                for (int j = 0; j < Num_y; j++)
                {
                    PictureBox pic = PictureHelper.Create(panel);
                    pic.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
                    pic.Location = new System.Drawing.Point(pic.Width * i + (pic.Width / 2), pic.Height * j + (pic.Height / 2));
                    pic.BackgroundImage = System.Drawing.Image.FromFile(@"Resource/1.png");
                }
            }
        }


        /// <summary>
        /// 更新UI
        /// </summary>
        /// <param name="time"></param>
        protected override void Draw(Time time)
        {
            base.Draw(time);
        }



        /// <summary>
        /// 更新游戏逻辑
        /// 更新UI请使用Draw
        /// </summary>
        /// <param name="time"></param>
        protected override void Update(Time time)
        {
            base.Update(time);
        }
    }
}
